package com.steak.order.dao;

import com.steak.common.domain.dataobject.tcc.Order;
import com.steak.common.domain.dto.UpdateOrderDTO;
import com.steak.common.result.Response;
import lombok.AllArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/116:54
 */
@Component
@AllArgsConstructor
public class OrderDao {
    private final JdbcTemplate jdbcTemplate;

    public Response saveOrder(Order order){
        System.out.println("saveOrder   -------------------------------------");
        String sql = "INSERT INTO `order`(order_id,user_id,commodity_id,`count`,money,status) VALUES("+"'"+order.getOrderId()+"'"+","+order.getUserId()+","+order.getCommodityId()+","+order.getCount()+","+order.getMoney()+","+order.getStatus()+")";
        jdbcTemplate.execute(sql);
        return new Response(200,"save order success",null);
    }

    public Response updateOrderStatus(UpdateOrderDTO updateOrderDTO) {
        String sql = "UPDATE `order` SET `status` = "+updateOrderDTO.getStatus()+" WHERE order_id = "+"'"+updateOrderDTO.getOrderId()+"'"+"";
        jdbcTemplate.update(sql);
        return new Response(200,"update order status success",null);
    }
}
